package com.hyt.it.ogt.controller.pj;


import com.hyt.exception.exception.BusinessRequestException;
import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.pj.progress.DkbObjectiveScoreDataDownloadLockKeyCreator;
import com.hyt.it.ogt.pj.progress.DkbProjectDataDownloadLockKeyCreator;
import com.hyt.it.ogt.pj.progress.ObjectiveScoreScoreDataDownloadLockKeyCreator;
import com.hyt.it.ogt.pj.progress.ProjectDataDownloadLockKeyCreator;
import com.hyt.it.ogt.pj.service.INewProjectService;
import com.hyt.loginfo.model.User;
import com.hyt.loginfo.service.IBaseLoginService;
import com.hyt.progress.creator.anno.ProgressAnno;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 评卷项目表 前端控制器
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
@ApiSort(value = 1)
@Api(tags = "1.评卷项目接口", value = "评卷项目接口")
@RestController
@RequestMapping("/project/cloudefile")
@Slf4j
public class NewProjectController extends BaseController {

    @Autowired
    private INewProjectService projectService;

    @Autowired
    private IBaseLoginService baseLoginService;


    @ApiOperationSort(value = 9)
    @ApiOperation(value = "1.5.1 项目数据下载", notes = "20000:成功, 51150101:获取不到当前登录人信息,51150102:下载文件失败,51150103:文件生成中请耐心等待")
    @GetMapping("projectDataDownload")
    @PreAuthorize("hasAuthority('gl_pj_listdownpj')")
    @ProgressAnno(timeoutSeconds = 24 * 60 * 60, canConcurrent = false, lockKeyCreator = ProjectDataDownloadLockKeyCreator.class)
    public void projectDataDownload(@RequestParam String projectId) throws Exception {
        log.info("# 项目数据下载参数 ： {}", projectId);
        User user = baseLoginService.getSysUser();
        if (null == user || StringUtils.isEmpty(user.getId())) {
            BusinessRequestException.throwException(51150101, "获取不到当前登录人信息");
        }
        projectService.projectDataDownload(projectId, user);
    }


    @ApiOperationSort(value = 10)
    @ApiOperation(value = "1.5.3 客观题成绩数据下载", notes = "20000:成功, 51150301:获取不到当前登录人信息, 51150302:下载文件失败, 51150303:文件生成中请耐心等待")
    @GetMapping("objectiveScoreDataDownload")
    @PreAuthorize("hasAuthority('gl_pj_listdownogcj')")
    @ProgressAnno(timeoutSeconds = 24 * 60 * 60, canConcurrent = false, lockKeyCreator = ObjectiveScoreScoreDataDownloadLockKeyCreator.class)
    public void objectiveScoreScoreDataDownload(@RequestParam String projectId) throws Exception {
        log.info("# 客观题成绩数据下载 ： {}", projectId);
        User user = baseLoginService.getSysUser();
        if (null == user || StringUtils.isEmpty(user.getId())) {
            BusinessRequestException.throwException(51150301, "获取不到当前登录人信息");
        }
        projectService.objectiveScoreDataDownload(projectId, user);
    }


    @ApiOperation(value = "1.9.1 大考版项目数据下载", notes = "20000:成功, 51150101:获取不到当前登录人信息,51150102:下载文件失败,51150103:文件生成中请耐心等待")
    @ApiOperationSort(value = 91)
    @GetMapping("dkbProjectDataDownload")
    @PreAuthorize("hasAuthority('gl_pj_downdkbpj')")
    @ProgressAnno(timeoutSeconds = 24 * 60 * 60, canConcurrent = false, lockKeyCreator = DkbProjectDataDownloadLockKeyCreator.class)
    public void dkbProjectDataDownload(@RequestParam String projectId) throws Exception {
        log.info("# 大考版项目数据下载参数 ： {}", projectId);
        User user = baseLoginService.getSysUser();
        if (null == user || StringUtils.isEmpty(user.getId())) {
            BusinessRequestException.throwException(51150101, "获取不到当前登录人信息");
        }
        projectService.dkbProjectDataDownload(projectId, user);
    }


    @ApiOperation(value = "1.9.2 大考版客观题成绩数据下载", notes = "20000:成功, 51150301:获取不到当前登录人信息, 51150302:下载文件失败, 51150303:文件生成中请耐心等待")
    @ApiOperationSort(value = 92)
    @GetMapping("dkbObjectiveScoreDataDownload")
    @PreAuthorize("hasAuthority('gl_pj_dkbcgcj')")
    @ProgressAnno(timeoutSeconds = 24 * 60 * 60, canConcurrent = false, lockKeyCreator = DkbObjectiveScoreDataDownloadLockKeyCreator.class)
    public void dkbObjectiveScoreDataDownload(@RequestParam String projectId) throws Exception {
        log.info("# 大考版客观题成绩数据下载 ： {}", projectId);
        User user = baseLoginService.getSysUser();
        if (null == user || StringUtils.isEmpty(user.getId())) {
            BusinessRequestException.throwException(51150301, "请先登录");
        }
        projectService.dkbObjectiveScoreDataDownload(projectId, user);
    }

}
